package com.cskaoyan.market.admin.controller;

import com.cskaoyan.market.admin.service.StatService;
import com.cskaoyan.market.db.vo.StatUserVo;
import com.cskaoyan.market.util.JacksonUtil;
import com.cskaoyan.market.util.ResponseUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

/**
 * @NAME: AdminStatController
 * @DESCRIPTION: TODO 用户统计控制器
 * @DATE: 2023/5/9 21:09
 * @AUTHOR: 刘超
 */
@RestController
@RequestMapping("/admin/stat")
public class AdminStatController{
    @Autowired
    StatService statService;

    @RequestMapping("/user")
    private void user(HttpServletRequest req, HttpServletResponse resp) throws IOException {
        ArrayList<String> columns = new ArrayList<>();
        columns.add("day");
        columns.add("users");
        HashMap<String, Object> result = new HashMap<>();
        result.put("columns", columns);
        List<StatUserVo> statUserVos = statService.statUser();
//        DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd");
//        LocalDateTime.parse(   , formatter)
//        statUserVos.add(new StatUserVo(LocalDate.parse("2023-05-09"),1));
//        statUserVos.add(new StatUserVo(LocalDate.parse("2023-05-10"),5));
        result.put("rows", statUserVos);
        resp.getWriter().println(JacksonUtil.getObjectMapper().writeValueAsString(ResponseUtil.ok(result)));
    }
    
}
